<?php
/*
  $Id$

  osCommerce, Open Source E-Commerce Solutions
  http://www.oscommerce.com

  Copyright (c) 2010 osCommerce

  Released under the GNU General Public License
*/

  require("includes/application_top.php");

  if ($cart->count_contents() > 0) {
    include(DIR_WS_CLASSES . 'payment.php');
    $payment_modules = new payment;
  }

  require(DIR_WS_LANGUAGES . $language . '/' . FILENAME_SHOPPING_CART);

  $breadcrumb->add(NAVBAR_TITLE, tep_href_link(FILENAME_SHOPPING_CART));

  require(DIR_WS_INCLUDES . 'template_top.php');
?>

<!--<h1><?php echo HEADING_TITLE; ?></h1>
-->
<div id="left" style="width:630px;">
<?php
  if ($cart->count_contents() > 0) {
?>

<?php echo tep_draw_form('cart_quantity', tep_href_link(FILENAME_SHOPPING_CART, 'action=update_product')); ?>
  
<?php
    include($templates_path . 'shoppingcart_bar.php');
	echo show_checkout_bar(HEADING_TITLE);
	echo '<div class="clear"></div>';
	$any_out_of_stock = 0;
    $products = $cart->get_products();
    for ($i=0, $n=sizeof($products); $i<$n; $i++) {
// Push all attributes information in an array
      if (isset($products[$i]['attributes']) && is_array($products[$i]['attributes'])) {
        while (list($option, $value) = each($products[$i]['attributes'])) {
          echo tep_draw_hidden_field('id[' . $products[$i]['id'] . '][' . $option . ']', $value);
          $attributes = tep_db_query("select popt.products_options_name, poval.products_options_values_name, pa.options_values_price, pa.price_prefix
                                      from " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_OPTIONS_VALUES . " poval, " . TABLE_PRODUCTS_ATTRIBUTES . " pa
                                      where pa.products_id = '" . (int)$products[$i]['id'] . "'
                                       and pa.options_id = '" . (int)$option . "'
                                       and pa.options_id = popt.products_options_id
                                       and pa.options_values_id = '" . (int)$value . "'
                                       and pa.options_values_id = poval.products_options_values_id
                                       and popt.language_id = '" . (int)$languages_id . "'
                                       and poval.language_id = '" . (int)$languages_id . "'");
          $attributes_values = tep_db_fetch_array($attributes);

          $products[$i][$option]['products_options_name'] = $attributes_values['products_options_name'];
          $products[$i][$option]['options_values_id'] = $value;
          $products[$i][$option]['products_options_values_name'] = $attributes_values['products_options_values_name'];
          $products[$i][$option]['options_values_price'] = $attributes_values['options_values_price'];
          $products[$i][$option]['price_prefix'] = $attributes_values['price_prefix'];
        }
      }
    }
?>

    <div class="yellow_bar">
        <div class="left_bg">
            <div class="right_bg">
                <div class="col_1 float_l"><?php echo TABLE_HEADING_PHOTO; ?></div>
                <div class="col_2 float_l"><?php echo TABLE_HEADING_PRODUCT_PRICE; ?></div>
                <div class="col_3 float_l"><?php echo TABLE_HEADING_QUANTITY; ?></div>
                <div class="col_4 float_l"><?php echo TABLE_HEADING_TOTAL; ?></div>
            </div>
        </div>
    </div>
    <div class="clear"></div>
    <table border="0" width="100%" cellspacing="0" cellpadding="0" class="checkout">

<?php

    for ($i=0, $n=sizeof($products); $i<$n; $i++) {
      $products_name = '  <tr>' .
                       '	<td width="15px"></td>' .
					   '	<td width="20px"><a href="' . tep_href_link(FILENAME_SHOPPING_CART, 'products_id=' . $products[$i]['id'] . '&action=remove_product') . '"><img src="includes/templates/kathmandu/images/remove_product.png" border="0" alt="" title="" /></a></td>'.
					   '    <td width="130px"><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $products[$i]['id']) . '">' . tep_image(DIR_WS_IMAGES . $products[$i]['image'], $products[$i]['name'], '', '67') . '</a></td>' .
                       '    <td valign="top" width="110px"><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $products[$i]['id']) . '"><strong>' . $products[$i]['name'] . '</strong></a>';

      $products_name .= '<br /><span>' . $currencies->display_price($products[$i]['final_price'], tep_get_tax_rate($products[$i]['tax_class_id']), 1) . '</span>';
	  if (STOCK_CHECK == 'true') {
        $stock_check = tep_check_stock($products[$i]['id'], $products[$i]['quantity']);
        if (tep_not_null($stock_check)) {
          $any_out_of_stock = 1;

          $products_name .= $stock_check;
        }
      }

      if (isset($products[$i]['attributes']) && is_array($products[$i]['attributes'])) {
        reset($products[$i]['attributes']);
        while (list($option, $value) = each($products[$i]['attributes'])) {
          $products_name .= '<br /><small><i> - ' . $products[$i][$option]['products_options_name'] . ' ' . $products[$i][$option]['products_options_values_name'] . '</i></small>';
        }
      }

      echo $products_name . '</td>' .
	  	   '		<td align="right" width="90">' . tep_draw_input_field('cart_quantity[]', $products[$i]['quantity'], 'size="4"') . tep_draw_hidden_field('products_id[]', $products[$i]['id']) . '</td>' .
           '        <td align="right" width="100"><strong>' . $currencies->display_price($products[$i]['final_price'], tep_get_tax_rate($products[$i]['tax_class_id']), $products[$i]['quantity']) . '</strong></td>' .
           '      </tr>';
    }
?>

    </table>
	<div class="checkout_summary">
        <div class="float_l" style="width:230px; overflow:hidden;"><input type="image" src="<?=$templates_path ?>images/update_product.png" /></div>
        <div style="text-align:right">
            <!--<span class="white">TOTAAL PRODUCT:</span>4<br />-->
            <strong><span class="white"><?php echo SUB_TITLE_SUB_TOTAL; ?></span> <?php echo $currencies->format($cart->show_total()); ?></strong><br />
            <!--<span class="white">VERZENDKOSTEN:</span>7,00&euro;-->
        </div>
    </div>

<?php
    if ($any_out_of_stock == 1) {
      if (STOCK_ALLOW_CHECKOUT == 'true') {
?>

    <p class="stockWarning" align="center"><?php echo OUT_OF_STOCK_CAN_CHECKOUT; ?></p>

<?php
      } else {
?>

    <p class="stockWarning" align="center"><?php echo OUT_OF_STOCK_CANT_CHECKOUT; ?></p>

<?php
      }
    }
	
	$href_back_category = FILENAME_DEFAULT;
	if (tep_session_is_registered('customer_id')) {
	  if($wholesaler == 1) {
		$href_back_category = FILENAME_WHOLESALE;
	  }
	}
?>

	<div style="clear:both;">
        <a href="<?=tep_href_link($href_back_category, 'cPath=0', 'SSL'); ?>" class="previous_bt"><span></span><?php echo TEXT_BACK_CATEGORY; ?></a>
        <a href="<?=tep_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL'); ?>" class="next_bt"><span></span><?php echo TEXT_CONTINUE; ?></a>
    </div>

<?php
    $initialize_checkout_methods = $payment_modules->checkout_initialization_method();

    if (!empty($initialize_checkout_methods) && false) {
?>

  <p align="right" style="clear: both; padding: 15px 50px 0 0;"><?php echo TEXT_ALTERNATIVE_CHECKOUT_METHODS; ?></p>

<?php
      reset($initialize_checkout_methods);
      while (list(, $value) = each($initialize_checkout_methods)) {
?>

  <p align="right"><?php echo $value; ?></p>

<?php
      }
    }
?>

</form>

<?php
  } else {
?>

<div class="contentContainer">
  <div class="contentText">
<?php
    include($templates_path . 'shoppingcart_bar.php');
	echo show_shoppingcart_bar(HEADING_TITLE);
	echo '<div class="clear"></div>';

    echo TEXT_CART_EMPTY;
?>

    <p align="right"><?php echo tep_draw_button(IMAGE_BUTTON_CONTINUE, 'triangle-1-e', tep_href_link(FILENAME_DEFAULT)); ?></p>
  </div>
</div>

<?php
  }
?>
</div>
<div id="right" style="width:255px; float:right; overflow:hidden;">
	<?php include($templates_path . 'col_right_categories.php');?>
   
</div>
<?php
  require(DIR_WS_INCLUDES . 'template_bottom.php');
  require(DIR_WS_INCLUDES . 'application_bottom.php');
?>
